# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gdbm
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.14.1
pkgrel=1
pkgdesc="GNU database library (mingw-w64)"
arch=('any')
url="https://www.gnu.org/software/gdbm/gdbm.html"
license=('GPL3')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-libiconv")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs')
source=(https://ftp.gnu.org/gnu/gdbm/${_realname}-${pkgver}.tar.gz{,.sig}
        'gdbm-1.10-zeroheaders.patch'
        'gdbm-win32-support.patch')
sha256sums=('cdceff00ffe014495bed3aed71c7910aa88bf29379f795abc0f46d4ee5f8bc5f'
            'SKIP'
            '64bfc37edfc5c71da142b3ca0843f71e169282da62f8440788ada1a88983cb04'
            '9a59270226944c5397c91b21fae7e5667c4766ca5d00cd4d94c5f8bb43417009')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}

  patch -Np1 -i ${srcdir}/gdbm-1.10-zeroheaders.patch
  patch -Np1 -i ${srcdir}/gdbm-win32-support.patch

  autoreconf --install --force
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --enable-shared \
    --disable-libgdbm-compat

  make
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make check || true
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
